home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / frasrc19.zip / HGCFRA.ASM < prev    next >
Assembly Source File  |  1991-09-13  |  7KB  |  269 lines

  1.     TITLE    Hercules Graphics Routines for FRACTINT
  2.  
  3. ;             required for compatibility if Turbo ASM
  4. IFDEF ??version
  5.     MASM51
  6.     QUIRKS
  7. ENDIF
  8.  
  9.     .MODEL    medium,c
  10.  
  11.     .8086
  12. .data
  13.  
  14. HGCBase     equ    0B000h        ;segment for HGC regen buffer page 0
  15.  
  16. herc_index    equ    03B4h
  17. herc_cntrl    equ    03B8h
  18. herc_status    equ    03BAh
  19. herc_config    equ    03BFh
  20.  
  21.  
  22. ; Hercules control/configuration register settings
  23.  
  24. scrn_on equ    08h
  25. grph    equ    02h
  26. text    equ    20h
  27. enable    equ    03h
  28.  
  29. .code
  30.  
  31. ;
  32. ;
  33. ; inithgc -  Initialize the HGC in graphics mode.
  34. ;        Code mostly from the Hercules Graphics Card Owner's Manual.
  35. ;
  36. inithgc PROC USES DI SI
  37.  
  38.     mov    al,enable        ; enable mode changes
  39.     mov    dx,herc_config        ; same as HGC FULL command
  40.     out    dx,al
  41.  
  42.     mov    al,grph         ; set graphic mode
  43.     lea    si,gtable        ; address of graphic parameters
  44.     mov    bx,0
  45.     mov    cx,4000h
  46.     call    setmd            ; call set mode common processing
  47.  
  48.     ret
  49.  
  50. inithgc ENDP
  51.  
  52. ;
  53. ; termhgc -  Restore the Hercules Graphics Card to text mode.
  54. ;        Code mostly from the Hercules Graphics Card Owner's Manual.
  55. ;
  56. termhgc PROC USES DI SI
  57.  
  58.     mov    al,text         ; set text mode
  59.     lea    si,ttable        ; get address of text parameters
  60.     mov    bx,720h
  61.     mov    cx,2000
  62.     call    setmd
  63.  
  64.     ret
  65.  
  66. termhgc ENDP
  67.  
  68. ;
  69. ; setmd - sets mode to graphic or text depending on al
  70. ;      si = address of parameter table
  71. ;      cx = number of words to be cleared
  72. ;      bx = blank value
  73. ;
  74. ;      from Hercules Graphics Card Owner's Manual
  75. ;
  76. setmd    PROC NEAR
  77. ;
  78.     push    bp
  79.     mov    bp,sp
  80.     push    ax
  81.     push    bx
  82.     push    cx
  83.  
  84. ;    change mode, but without screen on
  85.     mov    dx,herc_cntrl        ; get address of control register
  86.     out    dx,al            ; al has the mode byte
  87.  
  88. ;    initialize the 6845
  89.     mov    ax,ds
  90.     mov    es,ax            ; also point es:si to parameter table
  91.  
  92.     mov    dx,herc_index        ; get index register address
  93.     mov    cx,12            ; 12 parameters to be output
  94.     xor    ah,ah            ; starting from register 0
  95.  
  96. parms:    mov    al,ah            ; first output register number
  97.     out    dx,al
  98.  
  99.     inc    dx            ; get data register address
  100.     lodsb                ; get next byte from param. table
  101.     out    dx,al            ; output parameter data
  102.  
  103.     inc    ah            ; increment register number
  104.     dec    dx            ; restore index register address
  105.     loop    parms            ; go do another one
  106.  
  107. ;    now go clear the buffer
  108.     pop    cx            ; get number of words to clear
  109.     mov    ax,HGCBase        ; get address off video buffer
  110.     cld                ; set auto increment
  111.     mov    es,ax            ; set segment for string move
  112.     xor    di,di            ; start at offset 0
  113.     pop    ax            ; get blank value
  114.     rep    stosw            ; repeat store string
  115.  
  116. ;   turn screen on with page 0 active
  117.     mov    dx,herc_cntrl        ; get control register address
  118.     pop    ax            ; get the mode byte
  119.     add    al,scrn_on        ; set the screen-on bit
  120.     out    dx,al
  121.  
  122.     mov    sp,bp
  123.     pop    bp
  124.     ret
  125.  
  126. setmd    ENDP
  127. ;
  128. ; writehgc (x, y, c)  - write a dot at x, y in color color
  129. ;  x = x coordinate
  130. ;  y = y coordinate
  131. ;  color = color
  132. ;
  133. writehgc    PROC USES DI SI, x, y, color
  134.  
  135.     cmp    y,348            ; Clip for hardware boundaries
  136.     jge    WtDot030
  137.     cmp    x,720
  138.     jge    WtDot030
  139.  
  140.     lea    bx,HGCRegen        ;set up offset of regen scan line table
  141.     mov    ax,HGCBase        ;segment for regen buffer
  142.     mov    es,ax
  143.  
  144. ; calculate byte address of dot in regen buffer
  145.     mov    si,y        ;get y coordinate
  146.     shl    si,1        ;mult by 2 to get offset in Scan Line Table
  147.     mov    si,[bx][si]    ;get address of start of scan line from table
  148.     mov    ax,x        ;get x coordinate
  149.     mov    cl,3
  150.     shr    ax,cl        ;divide by 8 to get byte offset
  151.     add    si,ax        ;es:si has address of byte with the bit
  152. ; build the bit mask for the specific dot in the byte
  153.     mov    cx,x        ;get x coordinate
  154.     and    cx,0007h    ;get bit number within the byte
  155.     mov    al,80h        ;prepare bit mask
  156.     shr    al,cl        ;al has bit mask
  157. ; either turn on the bit or turn it off, depending on the color
  158.     cmp    word ptr color,0    ;turn off bit?
  159.     je    WtDot020    ;yes -- branch
  160. ; turn on the bit
  161.     or    byte ptr es:[si],al
  162.     jmp    short WtDot030
  163. WtDot020:
  164. ; turn off the bit
  165.     xor    al,0FFh
  166.     and    byte ptr es:[si],al
  167. WtDot030:
  168.     ret
  169.  
  170. writehgc    ENDP
  171. ;
  172. ; readhgc (x,y) - read a dot at x,y
  173. ;  x = x coordinate
  174. ;  y = y coordinate
  175. ;
  176. ;  dot value is to be returned in AX
  177. ;
  178. readhgc PROC USES DI SI, x,y
  179.  
  180.     lea    bx,HGCRegen        ;set up offset of regen scan line table
  181.     mov    ax,HGCBase        ;segment for regen buffer
  182.     mov    es,ax
  183.  
  184. ; calculate byte address of dot in regen buffer
  185.     mov    si,y        ;get y coordinate
  186.     shl    si,1        ;mult by 2 to get offset in Scan Line Table
  187.     mov    si,[bx][si]    ;get address of start of scan line from table
  188.     mov    ax,x        ;get x coordinate
  189.     mov    cl,3
  190.     shr    ax,cl        ;divide by 8 to get byte offset
  191.     add    si,ax        ;es:si has address of byte with the bit
  192.  
  193. ; build the bit mask for the specific dot in the byte
  194.     mov    cx,x        ;get x coordinate
  195.     and    cx,0007h    ;get bit number within the byte
  196.     mov    al,80h        ;prepare bit mask
  197.     shr    al,cl        ;al has bit mask
  198.  
  199. ; pick up the bit from the regen buffer
  200.     test    byte ptr es:[si],al
  201.     jz    readhgc020    ;branch if bit is zero
  202.     mov    ax,1        ;else return foreground bit value
  203.     jmp    short readhgc030
  204. readhgc020:
  205.     xor    ax,ax        ;bit is zero
  206. readhgc030:
  207.     ret
  208.  
  209. readhgc ENDP
  210.  
  211.  
  212. .data
  213.  
  214. gtable    db    35h,2dh,2eh,07h
  215.     db    5bh,02h,57h,57h
  216.     db    02h,03h,00h,00h
  217.  
  218. ttable    db    61h,50h,52h,0fh
  219.     db    19h,06h,19h,19h
  220.     db    02h,0dh,0bh,0ch
  221.  
  222.         ;offsets into HGC regen buffer for each scan line
  223. HGCRegen    dw    0,8192,16384,24576,90,8282,16474,24666
  224.         dw    180,8372,16564,24756,270,8462,16654,24846
  225.         dw    360,8552,16744,24936,450,8642,16834,25026
  226.         dw    540,8732,16924,25116,630,8822,17014,25206
  227.         dw    720,8912,17104,25296,810,9002,17194,25386
  228.         dw    900,9092,17284,25476,990,9182,17374,25566
  229.         dw    1080,9272,17464,25656,1170,9362,17554,25746
  230.         dw    1260,9452,17644,25836,1350,9542,17734,25926
  231.         dw    1440,9632,17824,26016,1530,9722,17914,26106
  232.         dw    1620,9812,18004,26196,1710,9902,18094,26286
  233.         dw    1800,9992,18184,26376,1890,10082,18274,26466
  234.         dw    1980,10172,18364,26556,2070,10262,18454,26646
  235.         dw    2160,10352,18544,26736,2250,10442,18634,26826
  236.         dw    2340,10532,18724,26916,2430,10622,18814,27006
  237.         dw    2520,10712,18904,27096,2610,10802,18994,27186
  238.         dw    2700,10892,19084,27276,2790,10982,19174,27366
  239.         dw    2880,11072,19264,27456,2970,11162,19354,27546
  240.         dw    3060,11252,19444,27636,3150,11342,19534,27726
  241.         dw    3240,11432,19624,27816,3330,11522,19714,27906
  242.         dw    3420,11612,19804,27996,3510,11702,19894,28086
  243.         dw    3600,11792,19984,28176,3690,11882,20074,28266
  244.         dw    3780,11972,20164,28356,3870,12062,20254,28446
  245.         dw    3960,12152,20344,28536,4050,12242,20434,28626
  246.         dw    4140,12332,20524,28716,4230,12422,20614,28806
  247.         dw    4320,12512,20704,28896,4410,12602,20794,28986
  248.         dw    4500,12692,20884,29076,4590,12782,20974,29166
  249.         dw    4680,12872,21064,29256,4770,12962,21154,29346
  250.         dw    4860,13052,21244,29436,4950,13142,21334,29526
  251.         dw    5040,13232,21424,29616,5130,13322,21514,29706
  252.         dw    5220,13412,21604,29796,5310,13502,21694,29886
  253.         dw    5400,13592,21784,29976,5490,13682,21874,30066
  254.         dw    5580,13772,21964,30156,5670,13862,22054,30246
  255.         dw    5760,13952,22144,30336,5850,14042,22234,30426
  256.         dw    5940,14132,22324,30516,6030,14222,22414,30606
  257.         dw    6120,14312,22504,30696,6210,14402,22594,30786
  258.         dw    6300,14492,22684,30876,6390,14582,22774,30966
  259.         dw    6480,14672,22864,31056,6570,14762,22954,31146
  260.         dw    6660,14852,23044,31236,6750,14942,23134,31326
  261.         dw    6840,15032,23224,31416,6930,15122,23314,31506
  262.         dw    7020,15212,23404,31596,7110,15302,23494,31686
  263.         dw    7200,15392,23584,31776,7290,15482,23674,31866
  264.         dw    7380,15572,23764,31956,7470,15662,23854,32046
  265.         dw    7560,15752,23944,32136,7650,15842,24034,32226
  266.         dw    7740,15932,24124,32316
  267.  
  268.     END
  269.